package org.fatewa.engine.exception;

import org.fatewa.engine.advice.protocol.RayquazaResponse;
import org.fatewa.engine.design.advice.AbstractExceptionProcessor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;

/**
 * {@link javax.validation} 包下检测出的参数错误
 *
 * @author fatewa
 */
public class DataIntegrityViolationProcessor
        extends AbstractExceptionProcessor<DataIntegrityViolationException> {
    @Override
    public RayquazaResponse map(DataIntegrityViolationException e) {
        RayquazaResponse response = new RayquazaResponse();
        return response
                .msg(e.getCause().getMessage())
                .code(HttpStatus.BAD_REQUEST);
    }
}
